package com.example.tnot.Teacher.CoursePart.CourseInternal.ClassDetail.VpFragment.ChapterDetail.ChapterDetailFragment;

import android.os.Bundle;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.tnot.R;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;
import com.example.tnot.Teacher.CoursePart.CourseInternal.ClassDetail.VpFragment.ChapterDetail.Adapter.CommentAdapter;
import com.example.tnot.Teacher.CoursePart.CourseInternal.ClassDetail.VpFragment.ChapterDetail.ItemBean.Comment;
import com.example.tnot.Teacher.CoursePart.CourseInternal.ClassDetail.VpFragment.CheckProgress.Adapter.CheckProgressAdapter;
import com.example.tnot.Util.ToastUtil;

import java.util.ArrayList;
import java.util.List;

public class ChapterDetailFragment extends BaseBackFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private String mParam1;
    private String mParam2;
    private View view;
    Button btn_view_progress;
    ImageView iv_back;
    TextView tv_title,tv_view_all,tv_non;
    RecyclerView rv_comments;
    private List<Comment> comments;


    public ChapterDetailFragment() {
    }
    public static ChapterDetailFragment newInstance(String param1, String param2) {
        ChapterDetailFragment fragment = new ChapterDetailFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.course_class_chapter_detail, container, false);
        //点击展开全部
        tv_view_all = view.findViewById(R.id.tv_view_all);
        comments = new ArrayList<>();
        InitData();
        String ChapterName = getArguments().getString("chapterName");
        tv_title = view.findViewById(R.id.tv_title);
        tv_title.setText(ChapterName);

        rv_comments = view.findViewById(R.id.rv_comments);
        rv_comments.setLayoutManager(new LinearLayoutManager(getActivity()));
        //有数据正常显示
        if(!comments.isEmpty()){
            CommentAdapter adapter = new CommentAdapter(comments);
            rv_comments.setAdapter(adapter);
            //若无评论数据,就显示"暂无更多评论"
        }else{
            rv_comments.setVisibility(View.GONE);
            tv_view_all.setVisibility(View.GONE);

            tv_non = view.findViewById(R.id.tv_non);
            tv_non.setVisibility(View.VISIBLE);
        }


        btn_view_progress = view.findViewById(R.id.btn_view_progress);
        btn_view_progress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_chapterDetailFragment_to_checkProgressFragment);
            }
        });

        tv_view_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showCustomToast(getActivity(), "您点击了");
            }
        });

        iv_back = view.findViewById(R.id.iv_back);
        iv_back .setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigateUp();
            }
        });
        return view;
    }

    //初始化数据
    private void InitData() {
//        comments.add(new Comment(R.drawable.avatar1,"qq毛","世界和平","10"));
//        comments.add(new Comment(R.drawable.example_face,"叶其浩大哥","我爱中国","30"));
//        comments.add(new Comment(R.drawable.example_face,"王怡心","福建烤老鼠","20"));
    }
}